<?php
function plugin_render() {
    $result = '';
    $error = '';
    if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['img']) && $_FILES['img']['error'] === UPLOAD_ERR_OK) {
        $type = mime_content_type($_FILES['img']['tmp_name']);
        $data = base64_encode(file_get_contents($_FILES['img']['tmp_name']));
        $result = "data:$type;base64,$data";
    } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $error = '请选择图片文件';
    }
    ?>
    <form method="post" enctype="multipart/form-data" class="space-y-4">
      <input type="file" name="img" accept="image/*" class="block">
      <button type="submit" class="bg-blue-500 text-white px-6 py-2 rounded">转换</button>
      <?php if ($error): ?>
        <div class="text-red-500"><?=htmlspecialchars($error)?></div>
      <?php endif; ?>
    </form>
    <?php if ($result): ?>
      <div class="mt-4">
        <img src="<?=$result?>" alt="预览" class="w-32 h-32 object-contain border rounded mb-2">
        <textarea class="w-full h-32 border rounded p-2 text-xs bg-gray-50" readonly><?=$result?></textarea>
      </div>
    <?php endif;
} 